﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;
using System.IO;
using System.Text;

namespace WechatModule.Tool
{
    public class XmlTool
    {
        public string ObjectToXmlStr<T>(T obj) {
            XmlSerializer serializer = new XmlSerializer(obj.GetType());
            MemoryStream stream = new MemoryStream();
            TextWriter writer = new StreamWriter(stream);
            serializer.Serialize(writer, obj);
            writer.Close();
            string str = Encoding.UTF8.GetString(stream.GetBuffer()).Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", "");
            str = str.Replace("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"", "").Replace("xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"", "").Replace(" ", "");//.Replace("\r\n","");
            str = str.Replace(obj.GetType().Name, "xml");
            return str;
        }

        
    }
}